package com.esd.device.controller;

import com.esd.common.pojo.R;
import com.esd.device.entity.Gateway;
import com.esd.device.service.GatewayService;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/gateway")
public class GatewayController {

    @Autowired
    private GatewayService gatewayService;

    // 获取所有配置的网关信息
    @GetMapping("getAll")
    public R list() {
        List<Gateway> list = gatewayService.list();
        return R.ok(list);
    }

    @PostMapping("addGateway")
    public R addGateway(@RequestBody Gateway gateway) throws SchedulerException {
        return gatewayService.addGateway(gateway);
    }

    @PutMapping("updateGateway")
    public R updateGateway(@RequestBody Gateway gateway) throws SchedulerException {
        return gatewayService.updateGateway(gateway);
    }

    @DeleteMapping("deleteGateway/{gatewayId}")
    public R deleteGateway(@PathVariable Integer gatewayId) throws SchedulerException {
        return gatewayService.deleteGateway(gatewayId);
    }

    @GetMapping("getById/{gatewayId}")
    public R getById(@PathVariable Integer gatewayId) {
        return R.ok(gatewayService.getById(gatewayId));
    }

    @GetMapping("checkLineGateway")
    public R checkLineGateway(@RequestParam(name = "lineName") String lineName){
        return gatewayService.checkGatewayConnection(lineName) ;
    }

}